package org.wgc.study;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@MapperScan("org.wgc.study.mapper")
@SpringBootApplication
@EnableAsync
@EnableTransactionManagement
// 开启定时任务
public class SpringBootMybatisApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringBootMybatisApplication.class, args);
        Environment environment = context.getBean(Environment.class);

        try {
            log.info("\n😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉😉\n\n\t" +
                    environment.getProperty("spring.application.name") + " 成功运行 ! Access URLs:\n\t" +
                    "内部接口访问：http://127.0.0.1:" + environment.getProperty("server.port") + "\n\t" +
                    "局域网接口访问：http://" + InetAddress.getLocalHost().getHostAddress() + ":" + environment.getProperty("server.port") +
                    "\n😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍😍\n");
        } catch (UnknownHostException e) {
            log.error("未知错误：{}", e.getMessage(), e);
        }
    }

    @Bean
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootMybatisApplication.class);
    }

}
